package com.lovi.myusercenter.exception;

import com.lovi.myusercenter.common.BaseResponse;
import com.lovi.myusercenter.common.ErrorCode;
import com.lovi.myusercenter.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.Ref;

@RestControllerAdvice
@Slf4j
public class GlobleExceptionHandler {
    /**
     * 业务异常
     * @param e
     * @return
     */
    @ExceptionHandler(BusinessException.class)
    public BaseResponse businessExceptionHandler(BusinessException e){
        log.error("业务异常 BusinessException:"+e.getMessage(),e);
        return Result.fail(e.getCode(),e.getMessage(),e.getDescription());
    }

    /**
     * 运行时异常
     * @param e
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    public BaseResponse runtimeExceptionHandler(RuntimeException e){
        log.error("运行时异常 RuntimeException",e);
        return Result.fail(ErrorCode.SYSTEM_ERROR);
    }


}
